﻿using MiniExcelLibs;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ConsoleApp10
{
    internal class TestCar
    {

        public static void Test()
        {
            string folderPath = @"C:\Users\humengjian\Desktop\新建文件夹\单选";

            // 获取指定文件夹下的所有文件
            string[] files = Directory.GetFiles(folderPath);

            // 遍历并输出每个文件的路径
            foreach (string file in files)
            {
                string fileName = Path.GetFileNameWithoutExtension(file);


                using (Stream stream = File.OpenRead(file))
                {
                    List<string> list = new List<string>();
                    var questionInputs = stream.Query<QuestionImportDataV2>().ToList();
                    if (questionInputs == null || questionInputs.Count == 0)
                    {
                        return;
                    }

                    List<QuestionOutData> questions2 = new List<QuestionOutData>();
                    int i = 0;
                    foreach (var questionInput in questionInputs)
                    {
                        if (questionInput.Content == null)
                        {
                            continue;
                        }
                        i++;
                        QuestionOutData questionOutData = new QuestionOutData()
                        {
                            Answer = questionInput.Answer,
                            Content = questionInput.Content.Replace("\n", ""),
                            OptionA = Regex.Replace(questionInput.OptionA.Trim().Replace("\n", "").Replace("\r", ""), @"^A\s*\.", ""),
                            OptionB = Regex.Replace(questionInput.OptionB.Trim().Replace("\n", "").Replace("\r", ""), @"^B\s*\.", ""),
                            OptionC = Regex.Replace(questionInput.OptionC.Trim().Replace("\n", "").Replace("\r", ""), @"^C\s*\.", ""),
                            OptionD = Regex.Replace(questionInput.OptionD.Trim().Replace("\n", "").Replace("\r", ""), @"^D\s*\.", ""),
                            Number = questionInput.Number,

                        };
                        questions2.Add(questionOutData);
                    }
                    using (var strem = File.Create($"{fileName}out.xlsx"))
                    {
                        strem.SaveAs(questions2);
                    }

                }
            }
        }
    }
}
